package com.elective.courseselect.controller;

import com.elective.courseselect.entity.CharacterMatchEntity;
import com.elective.courseselect.entity.CourseEntity;
import com.elective.courseselect.service.CharacterMatchService;
import com.elective.courseselect.utils.PageUtils;
import com.elective.courseselect.utils.R;
import com.elective.status.StatusCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 标签对应关系
 *
 * @author lee
 * @email 943204006@qq.ccom
 * @date 2021-09-04 19:23:06
 */
@RestController
@RequestMapping("courseselect/charactermatch")
public class CharacterMatchController {
    @Autowired
    private CharacterMatchService characterMatchService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = characterMatchService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CharacterMatchEntity characterMatch = characterMatchService.getById(id);
        return R.ok().put("characterMatch", characterMatch);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody CharacterMatchEntity characterMatch){
		characterMatchService.save(characterMatch);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody CharacterMatchEntity characterMatch){
		characterMatchService.updateById(characterMatch);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		characterMatchService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }


    //查看推荐选课
    @ApiOperation("查看推荐选课")
    @GetMapping("/searchRecommendChooseClass/{userId}")
    public R searchRecommendChooseClass(@PathVariable Integer userId){
        List<CourseEntity> list =  characterMatchService.searchRecommendChooseClass(userId);
        return R.ok(StatusCode.OK,"查看推荐选课成功").put("list", list);
    }

    //7.3.20 查看课程标签和性格标签对应关系
    /**
     *
     * @author Lee
     * @date 2021/12/12 0:19
     * @param searchId
     * @param type  0-拿性格标签查课程标签   1-拿课程标签查性格标签
     * @return com.elective.courseselect.utils.R
     */
    @ApiOperation("查看课程标签和性格标签对应关系")
    @GetMapping("/searchCharacterMatchReleation/{searchId}/{type}")
    public R searchCharacterMatchReleation(@PathVariable("searchId") Integer searchId , @PathVariable("type") Integer type){
        R r  =  characterMatchService.searchCharacterMatchReleation(searchId,type);
        return r;
    }

    //7.3.21. 修改课程标签和性格标签对应关系
    @ApiOperation("查看课程标签和性格标签对应关系")
    @GetMapping(value = {"/updateCharacterMatchReleation/{searchId}/{type}/{content}" , "/updateCharacterMatchReleation/{searchId}/{type}"})
    public R updateCharacterMatchReleation(@PathVariable("searchId") Integer searchId ,
                                           @PathVariable("type") Integer type ,
                                           @PathVariable(value = "content" , required = false)Integer[] content){
        R r  =  characterMatchService.updateCharacterMatchReleation(searchId,type,content);
        return r;
    }
}
